<!DOCTYPE html>
<title>Media Controls: caption button accessibility tests</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../media-controls.js"></script>
<video controls>
  <track src='../track/captions-webvtt/captions-fast.vtt' kind='captions' label="fast">
  <track src='../track/captions-webvtt/captions-rtl.vtt' kind='captions' label="rtl">
</video>
<script>
async_test(t => {
  var video = document.querySelector('video');
  enableTestMode(video);
  video.src = '../content/test.ogv';

video.onloadeddata = t.step_func(_ => {
    assert_true(isClosedCaptionsButtonEnabled(video));

    var captions_button = toggleClosedCaptionsButton(video);
    var captions_overflow_item = captionsOverflowItem(video);
    assert_not_equals(captions_button, null);
    assert_not_equals(captions_overflow_item, null);

    assert_equals(captions_button.getAttribute('aria-label'),
                  'show closed captions menu');

    assert_equals(captions_overflow_item.getAttribute('aria-label'),
                  'show closed captions menu');

    clickCaptionButton(video, t.step_func_done(function() {
      // Get the menu that displays the list of text tracks.
      var captionsList = textTrackMenu(video);
      assert_equals(captionsList.getAttribute('aria-label'), 'Options');
      var trackListHeader = textTrackListHeader(video);
      assert_equals(trackListHeader.getAttribute('aria-label'), 'hide closed captions menu');

      var offTrack = textTrackListItemAtIndex(video, -1);
      assert_equals(offTrack.innerText, 'Off');
      assert_equals(offTrack.getAttribute('role'), 'menuitemcheckbox');
      assert_equals(offTrack.getAttribute('aria-setsize'), '3');
      assert_equals(offTrack.getAttribute('aria-posinset'), '1');

      var fastTrack = textTrackListItemAtIndex(video, 0);
      assert_equals(fastTrack.innerText, 'fast');
      assert_equals(fastTrack.getAttribute('role'), 'menuitemcheckbox');
      assert_equals(fastTrack.getAttribute('aria-setsize'), '3');
      assert_equals(fastTrack.getAttribute('aria-posinset'), '2');

      var rtlTrack = textTrackListItemAtIndex(video, 1);
      assert_equals(rtlTrack.innerText, 'rtl');
      assert_equals(rtlTrack.getAttribute('role'), 'menuitemcheckbox');
      assert_equals(rtlTrack.getAttribute('aria-setsize'), '3');
      assert_equals(rtlTrack.getAttribute('aria-posinset'), '3');
    }));
  });
});
</script>
